import lsomerNum as IsomersNum
import copy

IsomersNum.substituentsNum = 1

def get1():
    return [5,0,0,0,0,0]  # 需要拼上最后一个0-substituentsNum

def get2():
    return [5,0,0,0,0,5]  # 需要拼上最后一个0-substituentsNum

# 最后一个一定是5
group27 = []
group27.append([0,5,0,0,0,5])
group27.append([0,0,5,0,0,5])
group27.append([0,5,0,5,0,5])
group27.append([5,0,0,5,0,5])
group27.append([5,0,5,5,0,5])
# group27.append([5,5,0,5,0,0])

# 所有铁路模板
allGroup = [get1(), get2()] + group27

def roateToMatchTemplate(losmerList):
    def doByOneTemplate(template):
        def isMatch(losmerList):
            for i in range(6):
                if (template[i]==5 and losmerList[i]!=5) or (template[i]!=5 and losmerList[i]==5):
                    return False
            return True

        def next(lsomerList):
            firstElm = lsomerList[0]
            for i in range(1, len(lsomerList)):
                lsomerList[i - 1] = lsomerList[i]
            lsomerList[len(lsomerList) - 1] = firstElm

        for i in range(6):
            if isMatch(losmerList):
                return losmerList
            next(losmerList)
        return None

    for t in allGroup:
        ret = doByOneTemplate(t)
        if not (ret is None):
            return ret
    return None

def recu(losmerList, addNum, chooseThis, nowSub=0):
    if addNum == IsomersNum.maxAddNum or nowSub == 6:  # 退出条件
        obj = IsomersNum.lsomer(roateToMatchTemplate(losmerList), addNum)
        obj.matchOrAdd()
    else:
        if chooseThis and losmerList[nowSub] != 5:
            for i in range(1, IsomersNum.substituentsNum+1):  # 可以放三种取代物
                newLosmerList = copy.copy(losmerList)
                newLosmerList[nowSub] = i
                recu(newLosmerList, addNum + 1, True, nowSub + 1)
                recu(newLosmerList, addNum + 1, False, nowSub + 1)
        else:
            recu(losmerList, addNum, True, nowSub + 1)
            recu(losmerList, addNum, False, nowSub + 1)

def isContinue1(losmerStr):
    return ('11' in losmerStr) or (losmerStr[0] == '1' and losmerStr[len(losmerStr) - 1] == '1')

# bHouseLogic：开启房子逻辑，会过滤掉连着1的但中心不为1的，默认值为False，不开启
# bSkipNo1：跳过没有1的，会过滤掉没有1的，默认值为False，不开启
def output1(bHouseLogic = False, bSkipNo1 = True):
    for lsomer2 in IsomersNum.allLsomer:
        losmerStr = lsomer2.toStr()
        # 条件1是否满足
        if not bHouseLogic:
            bCenter0 = True  # 不过滤，中心可以拼0、1
        else:
            bCenter0 = not isContinue1(losmerStr)  # false中心只能是1、不能是0
        # 条件2是否满足
        def isHave1Print(losmerStr):
            # 条件2是否满足
            if not bSkipNo1:
                bHave1 = True  # 不过滤，所有都输出
            else:
                bHave1 = '1' in losmerStr  # 有1才输出
            # 满足条件2输出
            if bHave1:
                print(losmerStr)
        # 填充个位
        isHave1Print(losmerStr + '1')
        if bCenter0:
            isHave1Print(losmerStr + '0')
    IsomersNum.allLsomer = []

print('>>>>> 处理[5,0,0,0,0,0]')
recu(get1(), 0, False)
output1()

print('>>>>> 处理[5,5,0,0,0,0]')
recu(get2(), 0, False)
output1()

def output37(startSub = 0, bHouseLogic = False, bSkipNo1 = True):
    for i in range(startSub, len(IsomersNum.allLsomer)):
        lsomer2 = IsomersNum.allLsomer[i]
        losmerStr = lsomer2.toStr() + '5'
        # 条件1是否满足
        if not bHouseLogic:
            bCenter5 = True  # 不过滤，中心可以是5
        else:
            bCenter5 = not isContinue1(losmerStr)  # false中心只能是1，不能是5，所以不显示
        # 条件2是否满足
        if not bSkipNo1:
            bHave1 = True  # 不过滤，所有都输出
        else:
            bHave1 = '1' in losmerStr  # 有1才输出
        # 满足都满足输出
        if bHave1 and bCenter5:
            print(losmerStr)

startSub = 0
for i in group27:
    originalList = copy.copy(i)
    print('>>>>> 处理' + str(originalList))
    recu(originalList, 0, False)
    output37(startSub)
    startSub = len(IsomersNum.allLsomer)
